/**
 *
 * @Author:   tiannanyihao
 * @Date:     2019-06-11 14:16
 * @Profile:  buyCar
 * @Project:  vue_004

 * @Description: 购物车state
 *
 */


const state = {
    coutn: 0,
    userLv: '用户级别'
}

const getters = {
    getCount: function (state) {
        return state.coutn
    },
    getUserLv: function (state) {
        return state.userLv
    }
}


const mutations = {
    plusCount: function (state) {
        state.coutn += 1
    },
    minusCount: function (state) {
        state.coutn -= 1
    },
    userLv: function (state, newValue) {
        let string = ''
        if (newValue <= 0) {
            string = '穷逼..'
        }
        if (newValue > 0 && newValue < 10) {
            string = '小资~'
        }
        if (newValue > 10 && newValue < 15) {
            string = '土豪!!'
        }
        if (newValue > 15 && newValue < 20) {
            string = '爸爸!!!'
        }
        state.userLv = string

    }
}

const actions = {
    doPlus: function (context) {
        context.commit('plusCount')
    },
    doMinus: function (context) {
        context.commit('minusCount')
    },
    setUserLv: function (context, newValue) {
        context.commit('userLv', newValue)
    }
}

export default {
    // 需要在其他组件使用getters/mutations等时,添加上模块名
    // 比如:
    // this.$store.dispatch('buyCar/doPlus'))
    namespaced: true, //用于在全局引用此文件里的方法时标识这一个的文件名
    state,
    getters,
    mutations,
    actions
}